import requests

from api.get_token import get_login_token

depart_id = "1530128634776473600"
class IhrmDepartmentApi(object):
    @staticmethod
    # 增加部门
    def add_depart(token, json_data):
        resp = requests.post(url="http://ihrm-test.itheima.net/api/company/department",
                             headers={"Authorization": token},
                             json=json_data)
        return resp
    # 修改部门

    @staticmethod
    def put_depart(token, emp_id, json_data):
        resp = requests.put(url="http://ihrm-test.itheima.net/api/company/department/" + emp_id,
                            headers={"Authorization": token},
                            json=json_data)
        return resp
    # 删除部门

    def delete_depart(token, emp_id):
        resp = requests.delete(url="http://ihrm-test.itheima.net/api/company/department/" + emp_id,
                            headers={"Authorization": token},
                            )
        return resp
    #  查看部门

    @staticmethod
    def get_depart(token, emp_id):
        resp = requests.get(url="http://ihrm-test.itheima.net/api/company/department/" + emp_id,
                            headers={"Authorization": token},
                            )
        return resp


if __name__ == '__main__':

    token = get_login_token()
    depart_id = "1530128634776473600"

    # 添加部门
    json_data = {"name":"研发部", "code":"13712834770"}
    resp = IhrmDepartmentApi.add_depart(token,json_data)
    print("添加部门",resp.json())

    #修改部门
    up_data = {"name": "测试部"}
    resp = IhrmDepartmentApi.put_depart(token,depart_id,up_data)
    print("修改部门",resp.json())

    # 查看部门
    resp = IhrmDepartmentApi.get_depart(token,depart_id)
    print("查看部门",resp.json())

    # 删除部门
    # resp = IhrmDepartmentApi.delete_depart(token,depart_id)
    # print("删除部门",resp.json())